home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI743.ASC < prev    next >
Text File  |  1992-05-13  |  3KB  |  133 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Turbo Pascal                           NUMBER  :  743
  9.   VERSION  :  1.0
  10.        OS  :  Windows
  11.      DATE  :  May 13, 1992                             PAGE  :  1/2
  12.  
  13.     TITLE  :  Loop Processing in Windows
  14.  
  15.  
  16.  
  17.  
  18.   There are two basic ways of handling loop processing in Windows
  19.   that would otherwise take away control (tie up processing of your
  20.   code and not allow other processes to run) of other running
  21.   Window's applications.  The first and probably the most flexible
  22.   approach is to write a processing loop and 'YIELD' to other
  23.   Windows application's request.  The second approach would be to
  24.   override TApplication's MessageLoop method and within the
  25.   MessageLoop call your process.
  26.  
  27.   'YIELD'
  28.   If your procedure that takes a while to execute contains some
  29.   sort of outer loop, make a call to a procedure that allows other
  30.   apps to run.  Your time consuming code might look something like:
  31.  
  32.        ...
  33.        While MoreToDo do
  34.        begin
  35.          YieldToOthers;
  36.          DoSomeProcessing;
  37.        end;
  38.  
  39.   A few notes concerning this procedure:
  40.  
  41.     *  The call to HALT may need to be modified to do any cleanup
  42.        required
  43.        (i.e.: close open files, etc.).
  44.  
  45.     *  You'll need to be sensitive to re-entrant issues.
  46.  
  47.   The procedure "YieldToOthers" would look like:
  48.  
  49.     Procedure YieldToOthers;
  50.     var
  51.       Msg : TMsg;
  52.     begin
  53.       While PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
  54.         if Msg.Message = WM_QUIT then begin
  55.           Application^.Done;
  56.           halt; {!!}
  57.         end;
  58.         TranslateMessage(Msg);
  59.         DispatchMessage(Msg);
  60.       end;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Turbo Pascal                           NUMBER  :  743
  75.   VERSION  :  1.0
  76.        OS  :  Windows
  77.      DATE  :  May 13, 1992                             PAGE  :  2/2
  78.  
  79.     TITLE  :  Loop Processing in Windows
  80.  
  81.  
  82.  
  83.  
  84.     end;
  85.  
  86.   'MessageLoop'
  87.   This is a replacement for the TApplication MessageLoop method.
  88.   It provides for an 'idle loop' where your program can
  89.   continuously process its own work, and yet still yield control to
  90.   windows when windows needs to do something.
  91.  
  92.     TMyApp = object(TApplication)
  93.       procedure MessageLoop; virtual;  { add this method to your }
  94.     end;      {*  descendant of TApplication  *}
  95.  
  96.     {*  just paste this in to your program  *}
  97.     procedure TMyApp.MessageLoop;
  98.     var
  99.       Message: TMsg;
  100.     begin
  101.  
  102.       while true do begin
  103.         if PeekMessage(Message, 0, 0, 0, pm_Remove) then begin
  104.           if Message.Message = wm_Quit then Exit;
  105.           TranslateMessage(Message);
  106.           DispatchMessage(Message);
  107.         end
  108.         else begin
  109.  
  110.           {**  do your stuff here  **}
  111.  
  112.         end;
  113.       end;
  114.  
  115.       Status := Message.WParam;
  116.  
  117.     end;
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.